for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
/**
* Movies
*/
'use strict'
const request = require('request-promise')
const __ = {
params: {},
requestAPI: function (url) {
return request({
uri: url,
qs: this.params,
json: true
})
}
const Movies = () => {
const proto = {
endpoint: {
list: 'https://yts.ag/api/v2/list_movies.json',
details: 'https://yts.ag/api/v2/movie_details.json'
},
setEndpoint: function (endpoint) {
if (typeof endpoint !== 'object') {
throw new Error('endpoint must be an object')
for (let i in endpoint) {
this.endpoint[i] = endpoint[i]
return this
setParams: function (params) {
if (typeof params !== 'object') {
throw new Error('params must be an object')
__.params = {}
for (let i in params) {
__.params[i] = params[i]
get: function () {
return __.requestAPI(this.endpoint.list)
findByGenre: function (genre) {
return this.setParams({genres: genre}).get()
findByQuality: function (quality) {
return this.setParams({quality: quality}).get()
findByRating: function (rating) {
return this.setParams({minimum_rating: rating}).get()
search: function (term) {
return this.setParams({query_term: term}).get()
findByID: function (id) {
this.setParams({
movie_id: id,
with_images: true,
with_cast: true
return __.requestAPI(this.endpoint.details)
return Object.create(proto)
module.exports = Movies()